.class Lcom/noshufou/android/su/provider/PermissionsProvider$SuDbOpenHelper;
.super Landroid/database/sqlite/SQLiteOpenHelper;
.source "PermissionsProvider.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/noshufou/android/su/provider/PermissionsProvider;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x2
    name = "SuDbOpenHelper"
.end annotation


# static fields
.field private static final DATABASE_NAME:Ljava/lang/String; = "su.db"

.field private static final DATABASE_VERSION:I = 0x4


# instance fields
.field final synthetic this$0:Lcom/noshufou/android/su/provider/PermissionsProvider;


# direct methods
.method constructor <init>(Lcom/noshufou/android/su/provider/PermissionsProvider;Landroid/content/Context;)V
    .locals 3
    .parameter
    .parameter "context"

    .prologue
    .line 466
    iput-object p1, p0, Lcom/noshufou/android/su/provider/PermissionsProvider$SuDbOpenHelper;->this$0:Lcom/noshufou/android/su/provider/PermissionsProvider;

    .line 467
    const-string v0, "su.db"

    const/4 v1, 0x0

    const/4 v2, 0x4

    invoke-direct {p0, p2, v0, v1, v2}, Landroid/database/sqlite/SQLiteOpenHelper;-><init>(Landroid/content/Context;Ljava/lang/String;Landroid/database/sqlite/SQLiteDatabase$CursorFactory;I)V

    .line 468
    return-void
.end method


# virtual methods
.method public onCreate(Landroid/database/sqlite/SQLiteDatabase;)V
    .locals 1
    .parameter "db"

    .prologue
    .line 472
    const-string v0, "CREATE TABLE IF NOT EXISTS apps (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid INTEGER, package TEXT, name TEXT,  exec_uid INTEGER, exec_cmd TEXT, allow INTEGER, notifications INTEGER, logging INTEGER, dirty INTEGER, UNIQUE (uid,exec_uid,exec_cmd));"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 473
    const-string v0, "CREATE TABLE IF NOT EXISTS logs (_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id INTEGER, date INTEGER, type INTEGER);"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 474
    return-void
.end method

.method public onUpgrade(Landroid/database/sqlite/SQLiteDatabase;II)V
    .locals 12
    .parameter "db"
    .parameter "oldVersion"
    .parameter "newVersion"

    .prologue
    .line 484
    move v10, p2

    .line 486
    .local v10, upgradeVersion:I
    const/4 v0, 0x1

    if-ne v10, v0, :cond_0

    .line 489
    const/4 v10, 0x2

    .line 492
    :cond_0
    const/4 v0, 0x2

    if-ne v10, v0, :cond_1

    .line 494
    :try_start_0
    const-string v0, "ALTER TABLE apps ADD COLUMN dirty INTEGER"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V
    :try_end_0
    .catch Landroid/database/sqlite/SQLiteException; {:try_start_0 .. :try_end_0} :catch_0

    .line 501
    :goto_0
    new-instance v11, Landroid/content/ContentValues;

    invoke-direct {v11}, Landroid/content/ContentValues;-><init>()V

    .line 502
    .local v11, values:Landroid/content/ContentValues;
    const-string v0, "dirty"

    const-string v1, "1"

    invoke-virtual {v11, v0, v1}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 503
    const-string v0, "apps"

    const/4 v1, 0x0

    const/4 v2, 0x0

    invoke-virtual {p1, v0, v11, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->update(Ljava/lang/String;Landroid/content/ContentValues;Ljava/lang/String;[Ljava/lang/String;)I

    .line 504
    iget-object v0, p0, Lcom/noshufou/android/su/provider/PermissionsProvider$SuDbOpenHelper;->this$0:Lcom/noshufou/android/su/provider/PermissionsProvider;

    #getter for: Lcom/noshufou/android/su/provider/PermissionsProvider;->mContext:Landroid/content/Context;
    invoke-static {v0}, Lcom/noshufou/android/su/provider/PermissionsProvider;->access$0(Lcom/noshufou/android/su/provider/PermissionsProvider;)Landroid/content/Context;

    move-result-object v0

    invoke-static {v0}, Lcom/noshufou/android/su/util/Util;->updatePermissionsDb(Landroid/content/Context;)V

    .line 505
    const/4 v10, 0x3

    .line 508
    .end local v11           #values:Landroid/content/ContentValues;
    :cond_1
    const/4 v0, 0x3

    if-ne v10, v0, :cond_3

    .line 509
    const-string v1, "apps"

    .line 510
    const/4 v0, 0x3

    new-array v2, v0, [Ljava/lang/String;

    const/4 v0, 0x0

    const-string v3, "_id"

    aput-object v3, v2, v0

    const/4 v0, 0x1

    const-string v3, "uid"

    aput-object v3, v2, v0

    const/4 v0, 0x2

    const-string v3, "name"

    aput-object v3, v2, v0

    .line 511
    const/4 v3, 0x0

    const/4 v4, 0x0

    const/4 v5, 0x0

    const/4 v6, 0x0

    const/4 v7, 0x0

    move-object v0, p1

    .line 509
    invoke-virtual/range {v0 .. v7}, Landroid/database/sqlite/SQLiteDatabase;->query(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v8

    .line 512
    .local v8, c:Landroid/database/Cursor;
    :cond_2
    :goto_1
    invoke-interface {v8}, Landroid/database/Cursor;->moveToNext()Z

    move-result v0

    if-nez v0, :cond_4

    .line 521
    invoke-interface {v8}, Landroid/database/Cursor;->close()V

    .line 522
    const/4 v10, 0x4

    .line 524
    .end local v8           #c:Landroid/database/Cursor;
    :cond_3
    return-void

    .line 495
    :catch_0
    move-exception v9

    .line 498
    .local v9, e:Landroid/database/sqlite/SQLiteException;
    const-string v0, "Su.PermissionsProvider"

    const-string v1, "dirty column already exists... wut?"

    invoke-static {v0, v1, v9}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0

    .line 513
    .end local v9           #e:Landroid/database/sqlite/SQLiteException;
    .restart local v8       #c:Landroid/database/Cursor;
    :cond_4
    const/4 v0, 0x2

    invoke-interface {v8, v0}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v0

    const-string v1, "unknown"

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_2

    .line 514
    new-instance v11, Landroid/content/ContentValues;

    invoke-direct {v11}, Landroid/content/ContentValues;-><init>()V

    .line 515
    .restart local v11       #values:Landroid/content/ContentValues;
    const-string v0, "name"

    iget-object v1, p0, Lcom/noshufou/android/su/provider/PermissionsProvider$SuDbOpenHelper;->this$0:Lcom/noshufou/android/su/provider/PermissionsProvider;

    #getter for: Lcom/noshufou/android/su/provider/PermissionsProvider;->mContext:Landroid/content/Context;
    invoke-static {v1}, Lcom/noshufou/android/su/provider/PermissionsProvider;->access$0(Lcom/noshufou/android/su/provider/PermissionsProvider;)Landroid/content/Context;

    move-result-object v1

    const/4 v2, 0x1

    invoke-interface {v8, v2}, Landroid/database/Cursor;->getInt(I)I

    move-result v2

    const/4 v3, 0x0

    invoke-static {v1, v2, v3}, Lcom/noshufou/android/su/util/Util;->getAppName(Landroid/content/Context;IZ)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v11, v0, v1}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 516
    const-string v0, "package"

    iget-object v1, p0, Lcom/noshufou/android/su/provider/PermissionsProvider$SuDbOpenHelper;->this$0:Lcom/noshufou/android/su/provider/PermissionsProvider;

    #getter for: Lcom/noshufou/android/su/provider/PermissionsProvider;->mContext:Landroid/content/Context;
    invoke-static {v1}, Lcom/noshufou/android/su/provider/PermissionsProvider;->access$0(Lcom/noshufou/android/su/provider/PermissionsProvider;)Landroid/content/Context;

    move-result-object v1

    const/4 v2, 0x1

    invoke-interface {v8, v2}, Landroid/database/Cursor;->getInt(I)I

    move-result v2

    invoke-static {v1, v2}, Lcom/noshufou/android/su/util/Util;->getAppPackage(Landroid/content/Context;I)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v11, v0, v1}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 517
    const-string v0, "apps"

    const-string v1, "_id=?"

    .line 518
    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/String;

    const/4 v3, 0x0

    const/4 v4, 0x0

    invoke-interface {v8, v4}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v4

    invoke-static {v4, v5}, Ljava/lang/String;->valueOf(J)Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    .line 517
    invoke-virtual {p1, v0, v11, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->update(Ljava/lang/String;Landroid/content/ContentValues;Ljava/lang/String;[Ljava/lang/String;)I

    goto :goto_1
.end method
